<template>
  <c-form :inline="true" :form="form" ref="refForm"></c-form>
  <c-user-task-listeners :bpmnElement="bpmnElement"></c-user-task-listeners>
</template>

<script>
import Form from "@/components/Form.vue";
import {mapActions, mapState} from "vuex";
import {processForm} from "@/components/bpmn/components/bpmnPropertiesPanel/forms";
import UserTaskHOC from "./userTaskComponents/UserTaskHOC.js";
import UserTask_Listeners from "./userTaskComponents/UserTask_Listeners.vue";

export default {
  name: "Properties_Process",
  components: {
    "c-form": Form,
    "c-user-task-listeners": UserTaskHOC(UserTask_Listeners)
  },
  data() {
    return {
      bpmnElement: null,
      form: processForm.call(this)
    }
  },
  inject: ["validate"],
  computed: mapState({
    typeList: state => state.flowDesignStore.typeList,
    modelFormList: state => state.flowDesignStore.modelFormList
  }),
  methods: {
    ...mapActions("flowDesignStore", ["getFlowTypeList", "getModelFormList"]),
    // 数据初始化
    async initData() {
      let {typeList, modelFormList} = this;
      if(!typeList || !modelFormList){
        const rst = await Promise.all([this.getFlowTypeList(), this.getModelFormList()])
        if(rst[0].status){
          typeList = rst[0].data;
        }else {
          this.$message({
            type: "warning",
            message: rst[0].message
          })
        }
        if(rst[1].status){
          modelFormList = rst[1].data;
        }else{
          this.$message({
            type: "warning",
            message: rst[1].message
          })
        }
      }

      this.form.items.type.options = typeList;
      this.form.items.formId.options = modelFormList;
    },

    dataReset(){
      this.form.models.id = this.businessObj?.id;
      this.form.models.name = this.businessObj?.name;
      this.form.models.desc = this.businessObj["desc"];
      this.form.models.type = this.businessObj["type"];
      this.form.models.formId = this.businessObj["formId"];
      this.form.models.var = this.businessObj["var"] && this.businessObj["var"].split(",");
      if(!this.businessObj.key){
        this.modeler.updateProperties({
          key: this.businessObj?.id
        });
      }
    }
  }
}
</script>